from apps.common.base.dao import BaseDao
from apps.pay.recordIncomes.serializers import *
from apps.user.dao import UserDao

class RecordIncomesDao(BaseDao):
    MODEL_CLASS = RecordIncomes
    SERI_CLASS = RecordIncomesBaseSerializer

    def create(self, data):
        serializers = RecordIncomesBaseSerializer(data=data)
        if serializers.is_valid():
            serializers.save()

            # 同步当前积分
            _user = UserDao().findOneByObjId(data.get('user'))
            _objId = serializers.data.get('id')
            self.update(_objId, {'balanceIncomes': _user.incomes})

        else:
            print('create --error--', self.MODEL_CLASS, serializers.errors)
            return serializers.errors